<?php

namespace App\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Events\AfterSheet;

class PayBillOrderExport implements FromCollection, WithHeadings, WithColumnWidths, WithEvents
{
    protected $data;

    public function __construct(Collection $data)
    {
        $this->data = $data;
    }

    public function collection()
    {
        return $this->data;
    }

    public function headings(): array
    {
        return [
            '账单编号',
            '代理商名称',
            '成本类型',
            '币种',
            '出账总金额',
            '实际成本',
            '生成账单日期',
            '提单数量',
            '账单状态',
            '开票状态',
            '账单生成人',
            '账单备注',
        ];

    }

    public function columnWidths(): array
    {
        // 设置每列的宽度
        return [
            'A' => 20,
            'B' => 20,
            'C' => 20,
            'D' => 15,
            'E' => 15,
            'F' => 20,
            'G' => 20,
            'G' => 20,
            'H' => 20,
            'I' => 15,
            'J' => 12,
            'K' => 20,
            'O' => 20,
            'P' => 20,
            'Q' => 20,
        ];
    }

    public function registerEvents(): array
    {
        return [
            AfterSheet::class => function(AfterSheet $event) {
                $event->sheet->getDelegate()->freezePane('A2');
            },
        ];
    }

}